package cn.iocoder.yudao.module.member.fans.controller.app;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.fans.service.MemberFansService;
import cn.iocoder.yudao.module.member.fans.vo.MemberFansCancelReqVO;
import cn.iocoder.yudao.module.member.fans.vo.MemberFansCreateReqVO;
import cn.iocoder.yudao.module.member.fans.vo.MemberFansRespVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "用户 App - 粉丝")
@RestController
@RequestMapping("/member/fans")
@Validated
public class AppMemberFansController {

    @Resource
    private MemberFansService memberFansService;

    @GetMapping("/is-follow")
    @Operation(summary = "是否已关注")
    @Parameter(description = "目标用户编号", required = true, example = "1")
    public CommonResult<Boolean> isFollow(@RequestParam("targetUserId") Long targetUserId) {
        boolean isFollow = memberFansService.isFollow(getLoginUserId(), targetUserId);
        return success(isFollow);
    }

    @PostMapping("/follow")
    @Operation(summary = "关注")
    public CommonResult<Boolean> doFollow(@Valid @RequestBody MemberFansCreateReqVO reqVO) {
        memberFansService.doFollow(getLoginUserId(), reqVO.getTargetUserId());
        return success(true);
    }

    @PostMapping("/cancel")
    @Operation(summary = "取关")
    public CommonResult<Boolean> cancelFollow(@Valid @RequestBody MemberFansCancelReqVO reqVO) {
        memberFansService.cancelFollow(getLoginUserId(), reqVO.getTargetUserId());
        return success(true);
    }

    @GetMapping("/fans-page")
    @Operation(summary = "获得我的粉丝分页")
    public CommonResult<PageResult<MemberFansRespVO>> getFansPage(@Valid PageParam reqVO) {
        PageResult<MemberFansRespVO> result = memberFansService.getMyFansPage(getLoginUserId(), reqVO);
        return success(result);
    }

    @GetMapping("/follow-page")
    @Operation(summary = "获得我的关注分页")
    public CommonResult<PageResult<MemberFansRespVO>> getFollowPage(@Valid PageParam reqVO) {
        PageResult<MemberFansRespVO> result = memberFansService.getMyFollowPage(getLoginUserId(), reqVO);
        return success(result);
    }

    @GetMapping("/friend-page")
    @Operation(summary = "获得我的朋友分页")
    public CommonResult<PageResult<MemberFansRespVO>> getFriendPage(@Valid PageParam reqVO) {
        PageResult<MemberFansRespVO> result = memberFansService.getMyFriendPage(getLoginUserId(), reqVO);
        return success(result);
    }

}
